package com.example.fairplay.newfpregistration.fragments;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.fairplay.newfpregistration.R;
import com.example.mylibrary.activity.BaseFragment;
import com.example.mylibrary.config.Config;
import com.example.mylibrary.config.Content;
import com.example.mylibrary.util.PreferencesUtils;
import com.example.mylibrary.util.ToastUtils;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by fairplay on 2018/5/31.
 * 网络设置fragment
 */

public class IntelSetttingFragment extends BaseFragment {
    @Bind(R.id.tv_http_ip)
    TextView tvHttpIp;
    @Bind(R.id.et_http_ip)
    EditText etHttpIp;
    @Bind(R.id.btn_save1)
    Button btnSave1;
    @Bind(R.id.tv_tcp_ip)
    TextView tvTcpIp;
    @Bind(R.id.et_tcp_ip)
    EditText etTcpIp;
    @Bind(R.id.tv_tcp_port)
    TextView tvTcpPort;
    @Bind(R.id.et_tcp_port)
    EditText etTcpPort;
    @Bind(R.id.btn_save2)
    Button btnSave2;
    private View mView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_inte_settting, container, false);
        ButterKnife.bind(this, mView);
        initObjects();
        initViews();
        initData();
        setListeners();
        return mView;

    }


    @Override
    protected void findViews() {


    }

    @Override
    protected void initObjects() {
        String http_url=PreferencesUtils.getString(Config.HTTP_SETTING,"");
        String tcp_ip=PreferencesUtils.getString(Config.TCP_IP,"");
        String tcp_port=PreferencesUtils.getString(Config.TCP_PORT,"");
        etHttpIp.setText(http_url);
        etTcpIp.setText(tcp_ip);
        etTcpPort.setText(tcp_port);
    }

    @Override
    protected void initViews() {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListeners() {

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.btn_save1, R.id.btn_save2})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_save1:
                String url=etHttpIp.getText().toString().trim();
                if(TextUtils.isEmpty(url)){
                    ToastUtils.Toast(mActivity,"请输入url");
                }else {
                    PreferencesUtils.putString(Config.HTTP_SETTING,url);
                }
                break;
            case R.id.btn_save2:
                String ip=etTcpIp.getText().toString().trim();
                String port=etTcpPort.getText().toString().trim();
                if(TextUtils.isEmpty(ip)||TextUtils.isEmpty(port)){
                    ToastUtils.Toast(mActivity,"ip或port不能为空");
                }else {
                    PreferencesUtils.putString(Config.TCP_IP,ip);
                    PreferencesUtils.putString(Config.TCP_PORT,port);
                }
                break;
        }
    }
}
